OBJECT_FILE = Tools.rel Number.rel NBuffer.rel Monitor.rel main.rel
OTHER_FILE = *.lst *.sym *.asm *.hex *.lk *.map *.mem *.rst
BIN_FILE = temp.bin
COMPILER = sdcc

SUDO = sudo
STCGAL = stcgal
MAKEBIN = makebin
# 生成的二进制文件大小限制：8192
MAKEBIN_ARGS = -s 8192
PACKIHX = packihx

SDCFLAGS = --code-size 8192 --iram-size 256 --xram-size 0

RM = rm
RM_FLAGS = -v -f

all: $(BIN_FILE)

install: $(BIN_FILE)
	$(SUDO) $(STCGAL) $(BIN_FILE)
	$(RM) $(RM_FLAGS) $(OTHER_FILE)

$(BIN_FILE) : %.bin : %.hex
	$(MAKEBIN) $(MAKEBIN_ARGS) $< > $@

%.hex : %.ihx
	$(PACKIHX) $< > $@

%.ihx : $(OBJECT_FILE)
	$(COMPILER) -o $@ $^ $(SDCFLAGS)

%.rel : %.c
	$(COMPILER) -c $< -I. $(SDCFLAGS)

.PHONY : clean
clean:
	$(RM) $(RM_FLAGS) $(BIN_FILE) $(OBJECT_FILE) $(OTHER_FILE)
